In this class, we will talk about model explainability but more in the context of data explainability or root cause analysis. In many cases building a very good machine learning model is not an ultimate goal. What is really wanted is the data understanding. A factory wants to know why the product is plagued with a defect, not to predict afterward if there is a defect or not. A football team wants to know which position is the best for scoring a goal, not what's the probability of scoring from a given position. And even when they want a prediction they would love to see the justification to trust the model. Often a nice plot is worth more than sophisticated machine-learning approaches.

You should already be familiar with many data visualization techniques so we will not train it now. I just want to share a less popular type of data analysis. Usually plotting the target against any feature is not helpful but after some modification, we might be able to see some patterns.

For each value, we can plot the average target for data:

Please note that for the line "above that value" the more left we go the higher fraction of data is covered. The same with the "below that value"

Ok, let's just train a model. We are not interested in top performance right now so we will skip hyperparameter optimization. Also, we want to find the pattern in the data we have, so we don't split the data into validation and test set.

Dalex is a python package for model explainability. We will use some of its functions to understand the data and the model better. First, we need to create an explainer model. Since we are not interested in checking the model performance but the relation between the data and the target we will use the whole dataset here. In the first case, we might want to use the testing set.

The first step will be feature importance. It's a basic analysis where we calculate the global impact of a feature. The idea in dalex default approach is to measure how much the model performance is worsening after removing this feature. Of course, it would require retraining the model, the optimal set of hyperparameters might be different and it might affect the results. To avoid these problems we do not retrain the model. Instead, we simulate its removal by assigning random values to it. To make it more realistic the values are not completely random, we just shuffle this column in a dataframe, do the prediction, check performance and repeat these steps multiple times.

Another useful tool is a partial dependency plot. For a given feature we observe what's the average output of our model for different values of this feature. For each considered value we set this value for each row in our dataframe and calculate an average prediction.

We can also create similar plots for single rows. Here for each column, we present what would be the output from the model assuming we keep all remaining values and change the value of this one selected feature.

SHAP values are equivalents of Shapley values for the predictive models. It estimates the effect of a particular value of a particular feature for a prediction of a considered row. It's also done by replacing this value with proper sampling and replacing this value and measuring the effect on the prediction.

The result is based on sampling so the result for the same row can vary

Task For each class find the most representative examples and plot breakdown for them.

There are other approaches that can be used for model explainability.

Task

Send it to gmiebs@cs.put.poznan.pl within 144 hours after the class is finished. Start the subject of the email with [IR]

Team members:

P.S.: Dataset can be found here: https://www.kaggle.com/datasets/muhammad4hmed/monkeypox-patients-dataset

Exploratory data analysis / Data Visualization

Data preprocessing

Brief report / Model explanation

Since most of the classifiers perform similarly in our case, it was decided to experiment on encoders in pipelines and eventually OneHotEncoder was chosen.

It does not effect the results that much, however it takes much more time to train model when it comes to OneHotEncoder based pipeline (several encoders as well as classifiers were tested).

Apart from that, OrdinalEncoder is found quite advantegeous as a part of data preprocessing when it comes to further dalex Explainer use, since it binarizes the data. Otherwise, model prediction functions (such as the plot above) would not be possible to use.